/*
 * ClienteDao.java
 *
 * Created on 4 de Junho de 2007, 23:19
 *
 */

package net.sf.jOpinionPoll.dao.jpa;

import java.util.List;

import net.sf.jOpinionPoll.dao.QuestaoDao;
import net.sf.jOpinionPoll.entity.Questao;

/**
 *
 * @author erico
 */
public class QuestaoDaoJpa extends DaoJpa implements QuestaoDao {

	/** Creates a new instance of ClienteDao */
    public QuestaoDaoJpa() {
    }
    
    private DaoJpaHelper<Questao> getDaoJpaHelper() {
    	return new DaoJpaHelper<Questao>(getEntityManager(), Questao.class);
    }

	@Override
	public void add(Questao newInstance) {
		getDaoJpaHelper().add(newInstance);
	}

	@Override
	public int count() {
		return getDaoJpaHelper().count();
	}

	@Override
	public Questao findByPk(Object primaryKey) {
		return getDaoJpaHelper().findByPk(primaryKey);
	}

	@Override
	public List<Questao> list(int firstResult, int maxResults) {
		return getDaoJpaHelper().list(firstResult, maxResults);
	}

	@Override
	public void remove(Questao questao) {
		getDaoJpaHelper().remove(questao);
		/*
		Query q1 = getDaoJpaHelper().getEntityManager().createQuery("delete Questao where id = :id");
		q1.setParameter("id", questao.getId());
		q1.executeUpdate();
		*/
		
		/*
		Query q1 = getDaoJpaHelper().getEntityManager().createNativeQuery("delete from questao where id = :id");
		q1.setParameter("id", questao.getId());
		Query q2 = getDaoJpaHelper().getEntityManager().createNativeQuery("delete from questionario_questao where questao_id = :id");
		q2.setParameter("id", questao.getId());

		q2.executeUpdate();
		q1.executeUpdate();
		*/
	}

	@Override
	public void set(Questao questao) {
		getDaoJpaHelper().set(questao);
	}
}